<?php
     include_once('../src/classes/class.mysql.php');  
     session_start();
     $db = new MySQL();
     $comtec_id_mainteiner = $_GET['id'];
     $comtec_id_machine    = $_GET['id_machine'];
     
     $result = $db->fetch_array($db->query("SELECT comtec_id_responsible,cod_mainteiner,comtec_id_configman FROM machines WHERE comtec_id_machine = $comtec_id_machine"));   
     $cod_mainteiner = $result['cod_mainteiner'];
     $comtec_id_responsible = $result['comtec_id_responsible'];
     $comtec_id_configman = $result['comtec_id_configman'];
          
     function extra($x){
      if ($x <= 9){
       $x = "0".$x;   
      }   
      return $x;   
     }
?>    
<fieldset class="curved">
 <legend>Ingresar</legend>
 <table style="margin: 10px auto; border-spacing: 10px;">
        <tr><td width="200"><label>M&aacute;quina</label></td>
            <td><input type="text" DISABLED size="40" value="<?=$cod_mainteiner;?>"/></td>
            <td width="200"><label>C&oacute;digo</label><a href='javascript:verOrdenesAnt(<?=$comtec_id_mainteiner?>);'>
               <img src='<? echo "http://".$_SERVER['HTTP_HOST']."/iconos/viewList.png"; ?>' alt='Ver ordenes' title='Ver ordenes' style='border: 0px;' /></a></td>
            <td><input type="text" size="40" id="cod_order" /></td>
        </tr>
        <tr>
            <td width="200"><label>Tipo de operaci&oacute;n</label></td>
            <td>
                <select id="operation_type" onchange="javascript:operation_type()" style="width:257px;">
                       <option value="0" selected>Selecci&oacute;n...</option>
                       <option value="1">Mantenci&oacute;n</option>
                       <option value="2">Emergencia</option>
                       <option value="3">Instalaci&oacute;n</option>
                       <option value="4">Reparaci&oacute;n</option>
                </select>
           </td>
           <td width="200"><label>Encargado<label></td>
           <td>
               <select id="comtec_id_responsible" style="width:257px;">
                <option value="0" selected>Selecci&oacute;n...</option>
                    <?
                        $responsible = $db->query("SELECT comtec_id_responsible, name, lastname1, lastname2, status_reg FROM responsible WHERE comtec_id_mainteiner = $comtec_id_mainteiner ");
                        while ($r = mysql_fetch_array($responsible, MYSQL_ASSOC))
                        {
                            if ($r['status_reg'] == 1)
                            {
                             if ($comtec_id_responsible==$r['comtec_id_responsible']){
                             echo "<option value=".$r['comtec_id_responsible']." selected>".$r['name']." ".$r['lastname1']." ".$r['lastname2']."</option>";
                             }else {
                              echo "<option value=".$r['comtec_id_responsible'].">".$r['name']." ".$r['lastname1']." ".$r['lastname2']."</option>";    
                             }
                             
                            }
                        }
                    ?>
               </select>
            </td>
           </tr>
           <tr>
               <td width="200"><label>Tareas</label></td>
               <td colspan=4><textarea id="tasks" rows="6" cols="91" style="resize:none"></textarea></td>
           </tr>
           <tr>
                <td width="200"><label>Notas</label></td>
                <td colspan=4><textarea id="notes" rows="2" cols="91" style="resize:none"></textarea></td>
           </tr>
           <tr>              
               <td width="200"><label>Fecha de inicio</label></td>
               <td>
                   <?
                     $optionsXML = simplexml_load_file("../xml/days.xml"); 
                     $options =  $optionsXML->xpath("//day/text()");
                     echo '<select id="op_day1" onchange="javascript:setDelay()">';
                     while(list( $key , $value) = each($options)) {      
                     if ($op_day == $key) { echo '<option value='.extra($key).' selected >' . $value . '</option>';}   
                     else {echo '<option value='.extra($key).'>' . $value . '</option>';}
                     }
                     echo '</select>';
                  ?>
                  <?
                      $optionsXML = simplexml_load_file("../xml/months.xml"); 
                      $options =  $optionsXML->xpath("//month/text()");
                      echo '<select id="op_month1" onchange="javascript:setDelay()">';
                      while(list( $key , $value) = each($options)) {  
                       if ($op_month == $key) { echo '<option value='.extra($key).' selected >' . $value . '</option>';}   
                       else {echo '<option value='.extra($key).'>' . $value . '</option>';}
                      }
                      echo '</select>';
                  ?>
                  <?
                      $optionsXML = simplexml_load_file("../xml/years.xml"); 
                      $options =  $optionsXML->xpath("//year/text()");
                      echo '<select id="op_year1" onchange="javascript:setDelay()">';
                      while(list($key,$value) = each($options)) {   
                       if ($op_year == $value) { echo '<option value='.$value.' selected >' . $value . '</option>';}   
                       else {echo '<option value='.$value.'>' . $value . '</option>';}
                      }
                      echo '</select>';
                  ?>
               </td>
           </tr>   
           <tr>
               <td width="200">
                   <label>Fecha de fin</label>
               </td>
               <td>
                   <?
                     $optionsXML = simplexml_load_file("../xml/days.xml"); 
                     $options =  $optionsXML->xpath("//day/text()");
                     echo '<select id="op_day2" onchange="javascript:setDelay()">';
                     while(list( $key , $value) = each($options)) {      
                     if ($op_day == $key) { echo '<option value='.extra($key).' selected >' . $value . '</option>';}   
                     else {echo '<option value='.extra($key).'>' . $value . '</option>';}
                     }
                     echo '</select>';
                  ?>
                  <?
                      $optionsXML = simplexml_load_file("../xml/months.xml"); 
                      $options =  $optionsXML->xpath("//month/text()");
                      echo '<select id="op_month2" onchange="javascript:setDelay()">';
                      while(list( $key , $value) = each($options)) {  
                       if ($op_month == $key) { echo '<option value='.extra($key).' selected >' . $value . '</option>';}   
                       else {echo '<option value='.extra($key).'>' . $value . '</option>';}
                      }
                      echo '</select>';
                  ?>
                  <?
                      $optionsXML = simplexml_load_file("../xml/years.xml"); 
                      $options =  $optionsXML->xpath("//year/text()");
                      echo '<select id="op_year2" onchange="javascript:setDelay()">';
                      while(list($key,$value) = each($options)) {   
                       if ($op_year == $value) { echo '<option value='.$value.' selected >' . $value . '</option>';}   
                       else {echo '<option value='.$value.'>' . $value . '</option>';}
                      }
                      echo '</select>';
                  ?>
               </td>
           </tr>  
           <tr>
               <td><input type="button" value="Guardar" onclick="javascript:saveOrder();" />
               <input type="button" value="Cancelar" onclick="javascript:loadMachines();" /></td>
           </tr>
          </table>
  <input type="hidden" id="comtec_id_machine" value="<?=$comtec_id_machine?>" />
  <input type="hidden" id="comtec_id_mainteiner" value="<?=$comtec_id_mainteiner?>" />
  <div id="result"></div> 
</fieldset>
